﻿
#region Using Directives

using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using EnvDTE;
using FeatureBuilder.ContribLib.Helpers;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Features;

#endregion

namespace FeaturBuilder.ContribLib.ValueProviders
{
    /// <summary>
    /// Search for the project specified by the "Path" property
    /// </summary>
    /// 
    [DisplayName("ProjectByPathProvider")]
    [Description("Search for the project based on the 'Path' property")]
    [Category("IDE")]
    public class ProjectByPathProvider : ValueProvider
    {
        /// <summary>
        /// Gets the ServiceProvider that we will use to get a reference to DTE.
        /// </summary>
        [Import(typeof(SVsServiceProvider))]
        public IServiceProvider ServiceProvider { get; private set; }

        public string Path { get; set; }

        #region Overrides

        /// <summary>
        /// Uses <see cref="DteHelper.FindProjectByPath"/> to search for the project specified by the "Path" property
        /// </summary>
        public override object Evaluate()
        {
            object selectedProject = null;
            DTE projectDTE = this.ServiceProvider.GetService(typeof(DTE)) as DTE;

            if (projectDTE != null)
            {
                selectedProject = DteHelper.FindProjectByPath(projectDTE.Solution, this.Path);
            }
            return selectedProject;
        }

        #endregion
    }
}

